
/// The dartboard web page... encapsulates html interaction
class Page {
  var runHandler;
  
  Page(runHandler) {
    this.runHandler = runHandler;
    query('#run').on.click.add(run);
  }

  /// Clear the log area
  clearLog() {
    query('#log').text = '';
  }

  /// Answer the soruce code entered by the user
  String get dartSource => query('#dartSource').text;

  /// Append the specified message to the log area of the screen
  log(String message) {
    query('#log')
      ..addText(message)
      ..addText('\n');
  }
  
  /// Disable the button while the handler is executing
  run(Event event) {
    query('#run').disabled = true;
    try {
      runHandler(event);
    } finally {
      query('#run').disabled = false;
    }
  }

  /// Set the source code for the user
  set dartSource(String source) {
    query('#dartSource').text = source;
  }

  /// Set the status message
  set status(String message) {
    query('#status').text = message;
  }
}